

***** Step 2: Prepare main SP95 data ****


clear
use "$path\Intermediary Data\Prix_SP9530_Level_DailyFULL.dta", clear

******
drop id_pdv_30num
gen id_pdv=substr(id_pdv_30,1,8)
replace id_pdv=subinstr(id_pdv, "_", "",.)

destring id_pdv, replace force
capture drop autoroute classif_num
merge m:1 id_pdv using "$path\Intermediary Data\data_PDV_autoroutes_supermarches_v3.dta" 
drop _merge



capture drop delta_lprix
capture drop delta_lprix_ht
capture drop inflation_ttc
capture drop inflation_ht

bysort id_pdv_30 (date_maj_num): gen delta_lprix=log(prix)-log(prix[_n-1])
bysort id_pdv_30 (date_maj_num): gen delta_lprix_ht=log(prix_ht)-log(prix_ht[_n-1])



replace delta_lprix=. if delta_lprix<-.0443759 | delta_lprix>.0393019
replace delta_lprix_ht=. if delta_lprix_ht<-.1004563 | delta_lprix_ht>.0897744 



merge m:m date_maj_num using "$path\Intermediary Data\DataReg_RotterdamBrent"


bysort id_pdv_30 (date_maj_num): replace gasoline_rotterdam_euro=gasoline_rotterdam_euro[_n-1] if gasoline_rotterdam_euro==.
bysort id_pdv_30 (date_maj_num): replace gasoline_rotterdam=gasoline_rotterdam[_n-1] if gasoline_rotterdam==.
drop _m

egen id=group(id_pdv_30)



gen j=int((date_maj_num - 17169)/7)
gen j2=int((date_maj_num - 17169+1))
gen j3=j2-j*7
drop j2


drop if j3<1
drop date_tokeep delta_lprix
drop   diesel_rotterdam*  id_pdv_30


save "$path\Intermediary Data\DataReg_SP95.dta", replace


